package com.laf.LAF.web;

import com.laf.LAF.domain.user.UserRepository;
import com.laf.LAF.domain.user.User;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by lenovo on 2017/9/25.
 */

@Controller
@RequestMapping("/aa")
public class TestController {
    @Autowired
    private UserRepository userRepository;

    @ApiOperation(value = "测试hello", notes = "测试")
    // @ResponseBody
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String index() {
        return "hello";
    }


    @ApiOperation(value = "测试list", notes = "测试")
    @ResponseBody
    @RequestMapping("/getlist")
    public String getUserList() {
        //userRepository.save(new User("AAA", 10, "123"));
        //  userRepository.save(new User("BBB", 20, "345"));
        int size = userRepository.findAll().size();
        return "Hello World test" + size;
    }

    @ResponseBody
    @ApiOperation(value = "获取用户详细信息", notes = "根据url的name来获取用户列表")
    @ApiImplicitParam(name = "name", value = "用户name", required = true, dataType = "String", paramType = "path")
    @RequestMapping(value = "/user/{name}", method = RequestMethod.GET)
    public String getUser(@PathVariable String name) {

        User users = userRepository.findByUsername(name);
        if (users != null) {
            return users.getUsername();
        } else {
            return null;
        }
    }


}
